﻿Imports System.Data.SqlClient

Public Class FrmMateriales

    'variable a nivel de clase para la manipulacion de datos
    Dim controller As New Class_RC_Controller.rc_Materiales
    Dim ancho As Decimal
    Dim largo As Decimal

    Private _codMaterial As Integer = 0

    Public Property codMaterial() As Integer
        Get
            Return _codMaterial
        End Get
        Set(value As Integer)
            _codMaterial = value
            txtcodmaterial.Text = value.ToString().PadLeft(4, "0")
        End Set
    End Property

    Public Sub inhabilitar()
        'inhabilitar los textbox
        Me.txtcodmaterial.Enabled = False
        Me.txtdescripcion.Enabled = False
        Me.txtcantidad.Enabled = False
        Me.txtcantmin.Enabled = False
        Me.txtcosto.Enabled = False
        Me.txtcantmax.Enabled = False
        Me.txtcantuni.Enabled = False
        Me.txtcostounidad.Enabled = False
        Me.txtancho.Enabled = False
        Me.txtlargo.Enabled = False
        Me.txtcantexuni.Enabled = False

        Me.cmbtipomaterial.Enabled = False
        Me.cmbUnidadMedida.Enabled = False
        'Me.cmbproveedor.Enabled = False
        Me.txtcodmaterial.BackColor = System.Drawing.Color.White
        Me.txtdescripcion.BackColor = System.Drawing.Color.White
        Me.txtcantmin.BackColor = System.Drawing.Color.White
        Me.txtcantidad.BackColor = System.Drawing.Color.White
        Me.txtcosto.BackColor = System.Drawing.Color.White
        Me.txtcantmax.BackColor = System.Drawing.Color.White
        Me.txtcantuni.BackColor = System.Drawing.Color.White
        Me.txtcostounidad.BackColor = System.Drawing.Color.White
        Me.txtlargo.BackColor = System.Drawing.Color.White
        Me.txtancho.BackColor = System.Drawing.Color.White
        Me.txtcantexuni.BackColor = System.Drawing.Color.White
        Me.cmbtipomaterial.BackColor = System.Drawing.Color.White

        'Me.cmbproveedor.BackColor = System.Drawing.Color.White
        'inhabilitar los botones
        Me.btnguardar.Enabled = False
        'Me.btnagregar.Enabled = True

        Me.btneliminar.Enabled = False
        'Me.btnsalir.Enabled = False
        Me.btncancelar.Enabled = False
        

    End Sub

    Public Sub habilitar()
        'habilitar controles para permitir la insersion
        Me.txtdescripcion.Enabled = True
        Me.txtcantmin.Enabled = True
        Me.txtcosto.Enabled = True
        Me.txtcantidad.Enabled = True
        Me.txtcantmax.Enabled = True
        'Me.cmbtipomaterial.Enabled = True
        'Me.cmbproveedor.Enabled = True
        Me.cmbUnidadMedida.Enabled = True
        'habilitar controles
        Me.btnguardar.Enabled = True
        'Me.btnagregar.Enabled = False

        Me.btneliminar.Enabled = True
        Me.btncancelar.Enabled = True
        'Me.btnsalir.Enabled = False
        

        'Me.btnbuscar.Enabled = False
    End Sub

    Public Sub limpiar()
        Me.txtcodmaterial.Text = ""
        Me.txtdescripcion.Text = ""
        Me.txtcantmin.Text = "0"
        Me.txtcosto.Text = "0"
        Me.txtcantmax.Text = "0"
        Me.txtcantidad.Text = "0"
        Me.txtcostounidad.Text = "0"
        Me.txtcantuni.Text = "0"
        Me.txtlargo.Text = "0"
        Me.txtancho.Text = "0"
        Me.txtcantuni.Text = "0"
        Me.txtcantexuni.Text = "0"

        Me.cmbtipomaterial.Text = ""
        'Me.cmbproveedor.Text = ""

        ancho = 0
        largo = 0
        txtlargo.Text = largo
        txtancho.Text = ancho

    End Sub

    Private Sub CargarMaterial()
        Try
            If codMaterial > 0 Then

                Dim ds As New DataTable
                ds = controller.get_Materiales_All(oiml.dbConn, codMaterial, "", 0)

                If Not ds Is Nothing Then
                    codMaterial = ds.Rows(0)("codMaterial")
                    cmbtipomaterial.SelectedValue = ds.Rows(0)("codTipoMaterial")
                    txtdescripcion.Text = ds.Rows(0)("descMaterial")
                    cmbUnidadMedida.SelectedValue = ds.Rows(0)("codUnidadMedida")

                    txtcosto.Text = ds.Rows(0)("costoMaterial")
                    txtcantidad.Text = ds.Rows(0)("cantExistente")
                    txtcantmin.Text = ds.Rows(0)("cantMinima")
                    txtcantmax.Text = ds.Rows(0)("cantMaxima")

                    'cmbproveedor.SelectedValue = ds.Rows(0)("codProveedor")
                    
                    lblUsuario.Text = ds.Rows(0)("usuario").ToString
                    lblfechaActualizacion.Text = ds.Rows(0)("fechaActualizacion_").ToString()

                    CargarDetalles()
                    habilitar()

                    txtcantidad.Enabled = False
                    'grpDetalles.Enabled = False
                    cmbUnidadMedida.Enabled = False
                    txtcantuni.Enabled = False
                    txtlargo.Enabled = False
                    txtancho.Enabled = False
                    txtcostounidad.Enabled = False
                    txtcantexuni.Enabled = False

                    If controller.Control_Materiales_Pedidos(oiml.dbConn, codMaterial) Then
                        btneliminar.Enabled = False
                        btnguardar.Enabled = False
                    End If

                End If

            Else

                txtcantidad.Enabled = True
                'grpDetalles.Enabled = True

                limpiar()
                lblUsuario.Text = oiml.Usuario
                lblfechaActualizacion.Text = Date.Now.ToShortDateString
                txtdescripcion.Focus()

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub llenarcbotipo()

        Dim dstipo As DataTable
        dstipo = controller.get_tipo_Materiales(oiml.dbConn)
        With Me.cmbtipomaterial
            .DataSource = dstipo
            .DisplayMember = "DescTipoMaterial"
            .ValueMember = "CodTipoMaterial"
        End With

    End Sub

    Private Sub llenarcbomedida()

        Dim dsunimedida As DataTable
        dsunimedida = controller.get_tipo_unidMedida(oiml.dbConn)
        With Me.cmbUnidadMedida
            .DataSource = dsunimedida
            .DisplayMember = "DescUnidadMedida"
            .ValueMember = "CodUnidadMedida"
        End With

    End Sub

    'Private Sub llenarcboproveedor()

    '    Dim dsProv As DataTable
    '    dsProv = controller.get_proveedores(oiml.dbConn)
    '    With Me.cmbproveedor
    '        .DataSource = dsProv
    '        .DisplayMember = "nombre"
    '        .ValueMember = "CodProveedor"
    '    End With

    'End Sub

    Private Sub CargarDetalles()
        Try
            If codMaterial > 0 Then

                Dim ds As New DataTable
                ds = controller.get_Materiales_Detalles_All(oiml.dbConn, codMaterial)

                If Not ds Is Nothing Then
                    txtcantuni.Text = ds.Rows(0)("cantUnidadMaterial")
                    txtcostounidad.Text = ds.Rows(0)("costoUnidad")
                    txtcantexuni.Text = ds.Rows(0)("cantExistente")
                    txtlargo.Text = ds.Rows(0)("largoMaterial")
                    txtancho.Text = ds.Rows(0)("anchoMaterial")
                End If

            Else
                txtcantuni.Text = "0"
                txtcostounidad.Text = "0"
                txtcantexuni.Text = "0"
                txtlargo.Text = "0"
                txtancho.Text = "0"

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Shadows Sub KeyUp(ByVal TextBoxs As System.Windows.Forms.TextBox, ByVal e As System.Windows.Forms.KeyEventArgs)

        'Teclas que Utilizaremos El cual solo son las numericas
        If e.KeyData = Keys.Space Or e.KeyData = Keys.Decimal Or _
         e.KeyData = Keys.NumPad0 Or e.KeyData = Keys.NumPad1 Or e.KeyData = Keys.NumPad2 Or e.KeyData = Keys.NumPad3 _
           Or e.KeyData = Keys.NumPad4 Or e.KeyData = Keys.NumPad5 Or e.KeyData = Keys.NumPad6 Or _
           e.KeyData = Keys.NumPad7 Or e.KeyData = Keys.NumPad8 Or e.KeyData = Keys.NumPad9 _
           Or e.KeyData = Keys.D0 Or e.KeyData = Keys.D1 Or e.KeyData = Keys.D2 Or e.KeyData = Keys.D3 Or _
           e.KeyData = Keys.D4 Or e.KeyData = Keys.D5 Or e.KeyData = Keys.D6 _
           Or e.KeyData = Keys.D7 Or e.KeyData = Keys.D8 Or e.KeyData = Keys.D9 Or e.KeyData = Keys.Tab Or e.KeyData = Keys.Enter _
           Or e.KeyData = Keys.OemMinus Or e.KeyData = Keys.Oemcomma Then
            'Programamos la tecla de Retroceso en el textbox
        ElseIf e.KeyData = Keys.Back And TextBoxs.Text.Length > 0 Then
            On Error Resume Next
            'Removemos un caracter mediante se presione la tecla Back
            TextBoxs.Text.Remove(TextBoxs.SelectionStart - 1)

            'si el textbox es menor que un caracter
        ElseIf TextBoxs.Text.Length < 1 Then
            'ponemos el textbox En Blanco
            TextBoxs.Text = String.Empty
            'ponemos la variable    NumerosYaescritos en Blanco

        Else
            'ponemos el textbox enblanco
            TextBoxs.Text = String.Empty
            'Hacemos Sonar un Beep para indicarle al usuario que ha presionado un caracter y no un Numero
            Beep()
            MsgBox("Introducir solo valores numericos")
        End If

    End Sub

    Private Sub FrmMateriales_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.llenarcbomedida()
        'Me.llenarcboproveedor()
        Me.llenarcbotipo()
        Me.CargarMaterial()
    End Sub

    Private Sub btneliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneliminar.Click
        Try
            If codMaterial > 0 Then
                If MessageBox.Show("Desea eliminar el registro seleccionado?", "Materiales", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

                    If controller.Delete_Materiales(oiml.dbConn, codMaterial) Then
                        Me.Close()

                    Else
                        MessageBox.Show("Error: " & controller.MessageError.Message, "Materiales", MessageBoxButtons.OK, MessageBoxIcon.Error)

                    End If

                End If
            End If

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

    End Sub

    Private Sub btncerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub btnagregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.limpiar()
        Me.habilitar()
        Me.btncancelar.Enabled = True
        Me.btnguardar.Enabled = True

        Me.cmbtipomaterial.Focus()
        'btnagregar.Enabled = False

    End Sub

    Private Function ValidarCampos() As Boolean

        Dim controlCampos As Boolean = False

        If Not IsNumeric(txtcantmin.Text) Then
            ErrorProvider.SetError(txtcantmin, "Campo numerico.")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtcantmin, "")
        End If        '

        If Not IsNumeric(txtcantuni.Text) Then
            ErrorProvider.SetError(txtcantuni, "Campo numerico.")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtcantuni, "")
        End If        '

        If Not IsNumeric(txtcosto.Text) Then
            ErrorProvider.SetError(txtcosto, "Campo numerico.")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtcosto, "")
        End If        '

        If Not IsNumeric(txtlargo.Text) Then
            ErrorProvider.SetError(txtlargo, "Campo numerico.")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtlargo, "")
        End If        '

        If Not IsNumeric(txtcantidad.Text) Then
            ErrorProvider.SetError(txtcantidad, "Campo numerico.")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtcantidad, "")
        End If        '

        If Not IsNumeric(txtcantmax.Text) Then
            ErrorProvider.SetError(txtcantmax, "Campo numerico.")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtcantmax, "")
        End If        '

        If Not IsNumeric(txtcantexuni.Text) Then
            ErrorProvider.SetError(txtcantexuni, "Campo numerico.")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtcantexuni, "")
        End If        '

        If Not IsNumeric(txtancho.Text) Then
            ErrorProvider.SetError(txtancho, "Campo numerico.")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtancho, "")
        End If        '

        If Not IsNumeric(txtcostounidad.Text) Then
            ErrorProvider.SetError(txtcostounidad, "Campo numerico.")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtcostounidad, "")
        End If        '

        '-----------------------------------------------------------------------------------------------

        If txtDescripcion.Text = "" Then
            ErrorProvider.SetError(txtDescripcion, "Campo obligatorio")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtDescripcion, "")
        End If

        If txtcantmin.Text = "" Then
            ErrorProvider.SetError(txtcantmin, "Campo obligatorio")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtcantmin, "")
        End If

        If txtcantmax.Text = "" Then
            ErrorProvider.SetError(txtcantmax, "Campo obligatorio")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtcantmax, "")
        End If

        If txtcantexuni.Text = "" Then
            ErrorProvider.SetError(txtcantexuni, "Campo obligatorio")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtcantexuni, "")
        End If

        If txtancho.Text = "" Then
            ErrorProvider.SetError(txtancho, "Campo obligatorio")
            controlCampos = True
        Else
            ErrorProvider.SetError(txtancho, "")
        End If
        '
        Return controlCampos

    End Function

    Private Sub btnguardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnguardar.Click
        If ValidarCampos() Then
            Exit Sub
        End If

        If codMaterial = 0 Then

            codMaterial = controller.Insert_Materiales(oiml.dbConn, cmbtipomaterial.SelectedValue, txtdescripcion.Text,
                                                       txtcantidad.Text, txtcosto.Text, txtcantmin.Text, txtcantmax.Text, oiml.idUsuario)
            If codMaterial > 0 Then

                If controller.Insert_Materiales_Detalle(oiml.dbConn, codMaterial, txtcantuni.Text, txtcostounidad.Text, txtcantexuni.Text, txtlargo.Text, txtancho.Text) Then
                    MessageBox.Show("Registro grabado con exito!", "Materiales", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    Me.DialogResult = Windows.Forms.DialogResult.OK
                    Me.Close()
                Else
                    MessageBox.Show("Error: " & controller.MessageError.Message, "Materiales - Detalle", MessageBoxButtons.OK, MessageBoxIcon.Error)

                End If

            Else
                MessageBox.Show("Error: " & controller.MessageError.Message, "Materiales", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End If

        Else

            If controller.Update_Materiales(oiml.dbConn, codMaterial, cmbtipomaterial.SelectedValue, txtdescripcion.Text,
                                                       txtcantidad.Text, txtcosto.Text, txtcantmin.Text, txtcantmax.Text, oiml.idUsuario) Then

                If controller.Update_Materiales_Detalle(oiml.dbConn, codMaterial, txtcantuni.Text, txtcostounidad.Text, txtcantexuni.Text, txtlargo.Text, txtancho.Text) Then
                    MessageBox.Show("Registro grabado con exito!", "Materiales", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    Me.DialogResult = Windows.Forms.DialogResult.OK
                    Me.Close()
                Else
                    MessageBox.Show("Error: " & controller.MessageError.Message, "Materiales - Detalle", MessageBoxButtons.OK, MessageBoxIcon.Error)

                End If

            Else
                MessageBox.Show("Error: " & controller.MessageError.Message, "Materiales", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End If

        End If

        limpiar()
        inhabilitar()

    End Sub

    Private Sub btncancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancelar.Click
        Me.Close()

    End Sub

    Private Sub btnsalir_Click(sender As System.Object, e As System.EventArgs)
        Me.Close()

    End Sub

    Private Sub txtcantuni_LostFocus(sender As Object, e As System.EventArgs) Handles txtcantuni.LostFocus
        
    End Sub

    Private Sub txtcantuni_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtcantuni.TextChanged

    End Sub

    'AL DAR ENTER PASAR AL SIGUIENTE TEXTBOX
    Private Sub cmbtipomaterial_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbtipomaterial.SelectedIndexChanged
        If cmbtipomaterial.Items.Count > 0 Then
            If cmbtipomaterial.SelectedValue.ToString() <> "" And cmbtipomaterial.SelectedValue.ToString() <> "System.Data.DataRowView" Then

                Dim idunimed As Integer
                idunimed = CInt(cmbtipomaterial.SelectedIndex)
                'cargartxtunimedida(DtTipoMate.Rows(idunimed)("CodUniMedida").ToString)
                HabUniMedida()

            End If

        End If

        

    End Sub

    Private Sub HabUniMedida()
        Dim unimedida As String
        unimedida = cmbUnidadMedida.Text

        Select Case unimedida

            Case "M CUADRADO"
                Dim area As Decimal
                Dim costo As Integer
                Dim cant As Integer
                txtancho.Enabled = True
                txtlargo.Enabled = True
                largo = txtlargo.Text
                ancho = txtancho.Text
                txtcantuni.Text = 0
                txtcantuni.Enabled = False
                If txtancho.Text <> 0 And txtlargo.Text <> 0 Then
                    area = largo * ancho
                    txtcantuni.Text = area
                    costo = CInt(txtcosto.Text)
                End If

                If area > 0 Then
                    txtcostounidad.Text = CInt(costo / area)
                    cant = CInt(txtcantidad.Text)
                    txtcantexuni.Text = cant * area
                End If

            Case "UNIDAD"
                txtancho.Text = 0
                txtlargo.Text = 0
                txtancho.Enabled = False
                txtlargo.Enabled = False
                txtcantuni.Text = 1
                txtcostounidad.Text = txtcosto.Text
                txtcantexuni.Text = txtcantidad.Text
            Case "METRO"
                txtancho.Text = 0
                txtlargo.Text = 0
                'txtcantuni.Text = 0
                txtancho.Enabled = False
                txtlargo.Enabled = False
                txtcantuni.Enabled = True
                If txtcantuni.Text <> "" Then
                    txtcostounidad.Text = txtcosto.Text / txtcantuni.Text
                    txtcantexuni.Text = txtcantuni.Text * txtcantidad.Text
                End If
            Case "CM CUBICO"
                txtancho.Text = 0
                txtlargo.Text = 0
                txtancho.Enabled = False
                txtlargo.Enabled = False
                txtcantuni.Enabled = True
                If txtcantuni.Text <> "" Then
                    txtcostounidad.Text = txtcosto.Text / txtcantuni.Text
                    txtcantexuni.Text = txtcantuni.Text * txtcantidad.Text
                End If
            Case "LITRO"
                txtancho.Text = 0
                txtlargo.Text = 0
                txtancho.Enabled = False
                txtlargo.Enabled = False
                txtcantuni.Enabled = True
                If txtcantuni.Text <> "" Then
                    txtcostounidad.Text = txtcosto.Text / txtcantuni.Text
                    txtcantexuni.Text = txtcantuni.Text * txtcantidad.Text
                End If
            Case "KILO"
                txtancho.Text = 0
                txtlargo.Text = 0
                txtancho.Enabled = False
                txtlargo.Enabled = False
                txtcantuni.Text = 1
                txtcostounidad.Text = txtcosto.Text
                txtcantexuni.Text = txtcantidad.Text
        End Select
        
    End Sub

    Private Sub txtcantidad_LostFocus(sender As Object, e As System.EventArgs) Handles txtcantidad.LostFocus
        HabUniMedida()
    End Sub

    Private Sub txtancho_LostFocus(sender As Object, e As System.EventArgs) Handles txtancho.LostFocus
        HabUniMedida()
    End Sub

    'Procedimientos para navegar a travez de los textbox con presionar la tecla ENTER
    Private Sub txtcodmaterial_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtcodmaterial.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub cmbtipomaterial_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles cmbtipomaterial.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    'Private Sub cmbproveedor_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles cmbproveedor.KeyPress
    '    If e.KeyChar = ChrW(Keys.Enter) Then
    '        e.Handled = True
    '        SendKeys.Send("{TAB}")
    '    End If
    'End Sub

    Private Sub txtdescripcion_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtdescripcion.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtcosto_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtcosto.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtcantidad_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs)
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtcantmin_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtcantmin.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtcantmax_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtcantmax.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtcantuni_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs)
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtlargo_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtlargo.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
        If e.KeyChar.ToString() = "." Then
            e.KeyChar = ","
        End If
    End Sub

    Private Sub txtancho_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtancho.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
        If e.KeyChar.ToString() = "." Then
            e.KeyChar = ","
        End If
    End Sub

    'Validad que solo se introduzcan valores numericos
    Private Sub txtcantidad_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        'Validar que solo se ingresen valores numericos
        Me.KeyUp(Me.txtcantidad, e)
    End Sub

    Private Sub txtcosto_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtcosto.KeyUp
        'Validar que solo se ingresen valores numericos
        Me.KeyUp(Me.txtcosto, e)
    End Sub

    Private Sub txtcantmin_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtcantmin.KeyUp
        'Validar que solo se ingresen valores numericos
        Me.KeyUp(Me.txtcantmin, e)
    End Sub

    Private Sub txtcantmax_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtcantmax.KeyUp
        'Validar que solo se ingresen valores numericos
        Me.KeyUp(Me.txtcantmax, e)
    End Sub

    Private Sub txtcantuni_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        'Validar que solo se ingresen valores numericos
        Me.KeyUp(Me.txtcantuni, e)
    End Sub

    Private Sub txtlargo_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtlargo.KeyUp
        'Validar que solo se ingresen valores numericos
        Me.KeyUp(Me.txtlargo, e)

    End Sub

    Private Sub txtancho_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtancho.KeyUp
        'Validar que solo se ingresen valores numericos
        Me.KeyUp(Me.txtancho, e)
    End Sub

    Private Sub txtcantuni_Leave(sender As System.Object, e As System.EventArgs) Handles txtcantuni.Leave
        HabUniMedida()
    End Sub

    
End Class
